import sys
import math

dic_file = sys.argv[1]
phigeo_file = sys.argv[2]

dics = {}
input_f = open(dic_file,'r')
c = 0
for lines in input_f:
    w = lines.strip().split('\t')
    dics[c] = w[-1]
    c = c + 1
input_f.close()

input_f = open(phigeo_file,'r')
for lines in input_f:
    w = lines.strip().split('\t')
    if len(w) !=2:
        continue
    geo = w[0]
    geo_topics = {}
    for words in w[1].split(' '):
        s = words.split(':')
        word_id = int(s[0])
        value =float(s[1])
        geo_topics[word_id] = value
    if len(geo_topics)<50:
        continue
    buffer = []
    for word_id,value in geo_topics.iteritems():
        buffer.append((value,word_id))
    buffer.sort()
    buffer = [(word_id,value) for value,word_id in buffer]
    buffer.reverse()
    s = str(geo)+'\n\t'
    for i in range(0,50):
        s = s + dics[buffer[i][0]] + ' '
    print s
input_f.close()
